﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;

namespace DelonixRegia.Classes.MiniBarItems
{
    public class MiniBarDBManager
    {
        private const string connectionString = "Data Source=.; Initial Catalog=DelonixRegia; Integrated Security=True;";

        public static MiniBar getMiniBarItemByID(int id)
        {
            MiniBar mb = null;

            try
            {
                SqlConnection conn = new SqlConnection(connectionString);
                conn.Open();

                SqlCommand comm = new SqlCommand();
                comm.Connection = conn;

                comm.CommandText = "SELECT * FROM MiniBar WHERE itemID=@id";
                comm.Parameters.AddWithValue("@id", id);

                SqlDataReader dr = comm.ExecuteReader();

                if (dr.Read())
                {
                    mb = new MiniBar();
                    mb.itemID = id;
                    mb.name = (string)dr["name"];
                    mb.description = (string)dr["description"];
                    mb.cost = Convert.ToDecimal(dr["cost"]);
                }

                dr.Close();
                conn.Close();
            }
            catch (SqlException e)
            {
                throw e;
            }

            return mb;
        }
    }
}